<script type="text/javascript">
	$(function() {

		var $table_id = $("#firm-post-list");
		var user = {
			getQueryCondition: function(data) {
				var param = {};
				param.yearAndMonth = $.trim($("#yearAndMonth").val());
				param.areaCode = $.trim($("#area").val());
				param.pageNumber = data.start;
				param.pageSize = data.length;
				param.draw = 1;
				return param;
			}
		};

	    var dataTable = $table_id.DataTable({
            dom: '<".table_area_top" B and >t<".table_area_bottom" pi>',
            Filter: false, //列筛序功能
            searching: false,//本地搜索
            ordering: true, //排序功能
            Info: true,//页脚信息
            lengthMenu: [15],//定义每页显示数据数量
            scrollY: "auto",
            Paginate: true, //翻页功能
            sortable: false,
            processing: true,
            serverSide: true,
			ajax: function(data, callback) { //ajax配置为function,手动调用异步查询
				$.ajax({
					type: "post",
					url: "/guidance_service/front/guidance/guidanceList.do",
					data: user.getQueryCondition(data),
					cache: false, //禁用缓存
					dataType: "json",
					success: function(result) {
						//封装返回数据，这里仅演示了修改属性名
						var returnData = {};
						returnData.recordsTotal = result.ext.recordsTotal;
						returnData.recordsFiltered = result.ext.recordsFiltered; //后台不实现过滤功能，每次查询均视作全部结果
						returnData.data = result.data;
						callback(returnData);
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {
						layer.msg("查询失败,请检查搜索条件！", {
							icon: 2,
							time: 1000
						});
					}
				});
			},
			//使用对象数组，一定要配置columns，告诉 DataTables 每列对应的属性
			//data 这里是固定不变的，id，name，age，sex等为你数据里对应的属性
			columns: [{
					data: "guidanceId",
					render: function(data) {
						return '<input type="checkbox" name="guidanceId" value="' + data + '" class="guidanceId">';
					}
				},
				{
					data: "guidanceName",
					render: function(data) {
						return data || "";
					}
				},
				{
					data: "major",
					render: function(data) {
						return data || "";
					}
				},
				{
					data: "year", //
					render: function(data) {
						return data || "";
					}
				},
				{
					data: "month", //
					render: function(data) {
						return data || "";
					}
				},
				{
					data: "areaCode", //
					render: function(data) {
						return data || "";
					}
				},
				{
					data: "explains", //发文机关
					render: function(data) {
						return data || "";
					}
				},
				{
					data: "createUserId",
					render: function(data) {
						//sessionStorage.setItem("fieldId",data)
						//return sessionStorage.getItem(data);
						return data || "";
					}
				},
				{
					data: "state",
					render: function(data) {
						return data;
					}
				},
				{
					data: "updateTime",
					render: function(data) {
						return data || "";
					}
				},
				{
					data: "guidanceId",
					render: function(data, type, row) {
						return '<a style="text-decoration:none" onClick="policies_shenhe(this,' + data + ')" href="javascript:;" title="审核">审核</a>' +
							'<a style="text-decoration:none" class="ml-5" onClick="guidance_edit(this,\'add.html?guidanceId=' + data + '\')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>' +
							'<a style="text-decoration:none" class="ml-5" onClick="guidance_del(this,' + data + ')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>';
					}
				}
			],
			language: { //国际语言转化
				aria: {
					sortAscending: " - click/return to sort ascending",
					sortDescending: " - click/return to sort descending"
				},
				lengthMenu: "显示 _MENU_ 记录",
				zeroRecords: "对不起，查询不到任何相关数据",
				emptyTable: "未有相关数据",
				loadingRecords: "正在加载数据-请等待...",
				info: "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录。",
				infoEmpty: "当前显示0到0条，共0条记录",
				infoFiltered: "（数据库中共为 _MAX_ 条记录）",
				processing: " 正在加载数据...",
				//多语言配置文件，可将oLanguage的设置放在一个txt文件中，例：Javascript/datatable/dtCH.txt
				paginate: {
					first: "首页",
					previous: " 上一页 ",
					next: " 下一页 ",
					last: " 尾页 "
				}
			},
			"drawCallback": function (settings) {
                var api = this.api();
               // console.log(api.rows({page: 'current'}).data());
            }
		});
		$("#searchButton").on("click", function () {
            dataTable.draw();
        });

        $("body").on("change", ":checkbox", function () {
            if ($(this).is("[name='checkBtn']")) {
                //全选
                $(":checkbox", $table_id).prop("checked", $(this).prop("checked"));
            } else {
                //一般复选
                var checkbox = $("tbody :checkbox", $table_id);
                $(":checkbox[name='checkBtn']", $table_id).prop('checked', checkbox.length == checkbox.filter(':checked').length);
            }
        }).on("click", ".td-checkbox", function (event) {
            //点击单元格即点击复选框
            !$(event.target).is(":checkbox") && $(":checkbox", this).trigger("click");
        })
	});
</script>